<template>
  <div>
    <div class="ibox-content no-border no-padding-bottom">
      <el-col>
        <el-form :inline="true" :model="filterForm" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="filterForm.id"></el-input>
          </el-form-item>
          <el-form-item label="标签名称">
            <el-input v-model="filterForm.app_name"></el-input>
          </el-form-item>
          <el-form-item label="投诉内容">
            <el-input v-model="filterForm.content"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="filterForm.status">
              <el-option label='全部' value=""></el-option>
              <el-option label="未处理" value="0"></el-option>
              <el-option label="处理中" value="1"></el-option>
              <el-option label="已处理" value="2"></el-option>
            </el-select>
          </el-form-item>
          <br>
          <el-form-item class="el-col-offset-9">
            <el-button @click.native="filterClick" type="primary">查询</el-button>
            <el-button @click.native="resetFilterForm('filterForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </div>
    <div class="ibox-content">
      <!--表格-->
      <el-table
              ref="multipleTable"
              :data="arrList"
              size="medium"
              border
              highlight-current-row
              tooltip-effect="dark"
              style="width: 100%"
              :max-height="500"
              v-loading="tableLoading"
              @selection-change="handleSelectionChange"
      >
        <el-table-column prop="id" label="ID" width="80"></el-table-column>
        <el-table-column prop="app_name" label="产品名称"></el-table-column>
        <el-table-column prop="content" label="投诉内容"></el-table-column>
        <el-table-column prop="status" label="状态" width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.status ==0" class="red">未处理</span>
            <span v-if="scope.row.status ==1" class="warning">处理中</span>
            <span v-if="scope.row.status ==2" class="green">已处理</span>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间" width="160"></el-table-column>
        <el-table-column prop="updated_at" label="处理时间" width="160"></el-table-column>
        <el-table-column label="操作" align="center" width="130" fixed="right">
          <template slot-scope="scope">
            <el-tooltip @click.native="handleEdit(scope.row)" :enterable="false" effect="dark" content="编辑"
                        placement="top-start">
              <el-button type="primary" plain size="mini" icon="el-icon-edit"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!--分页工具条-->
      <div v-show="arrList.length>0" style="margin-top: 18px;text-align: center">
        <el-pagination
                @current-change="handleCurrentChange"
                :current-page="pageInfo.currPage"
                :page-sizes="[20]"
                :page-size="pageInfo.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageInfo.totalCount">
        </el-pagination>
      </div>
    </div>


    <!-- 添加标签 -->
    <el-dialog width="36%" title="处理产品投诉" :visible.sync="addTagFormVisible" @close="closeDialog"
               :close-on-click-modal="false">
      <el-form :rules="addTagFormRule" :model="addTagForm" ref="addTagForm" size="small">
        <el-form-item label="投诉内容">
          <el-input :disabled="true" type="textarea" v-model="addTagForm.content"></el-input>
        </el-form-item>
        <el-form-item label="处理结果" prop="process_result">
          <el-input type="textarea" placeholder="请输入处理结果" v-model="addTagForm.process_result"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="closeDialog" size="small">关闭</el-button>
        <el-button type="primary" @click.native="addTagFormSave('addTagForm')" size="small">保存</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
  import {appComplaintList, appComplaintSave} from "../../api/product";

  export default {
    name: "AppComplaint",
    data() {
      return {
        filterForm: {},
        arrList: [],
        pageInfo: {
          totalPage: 0,// 总页数
          totalCount: 0,// 总条数
          pageSize: 0,// 每页条数
          currPage: 1// 当前页
        },
        tableLoading: false,
        tableSelectData: [],
        addTagForm: {},
        addTagFormRule: {
          process_result: [
            {required: true, message: '不能为空'}
          ],
        },
        addTagFormVisible: false,
        tagTitle: '',
      }
    },
    created() {
      this.getComplaintList();
    },
    methods: {
      //查询
      filterClick() {
        this.pageInfo.currPage = 1;
        this.getComplaintList();
      },
      //重置
      resetFilterForm(form) {
        this.$refs[form].resetFields();
        this.filterForm = {};
        this.pageInfo.currPage = 1;
        this.getTagList();
      },
      //分页
      handleCurrentChange(val) {
        // console.log(val);
        this.pageInfo.currPage = val;
        this.getTagList();
      },
      handleSelectionChange(data) {
        this.tableSelectData = data;
      },
      getComplaintList() {
        this.tableLoading = true;
        appComplaintList({
          page: this.pageInfo.currPage,
          ...this.filterForm
        }).then(res => {
          this.tableLoading = false;
          const {listData, page} = res.data;
          this.arrList = listData;
          this.pageInfo = page
        }).catch(() => {
          this.tableLoading = false
        })
      },
      //添加标签
      handleAdd() {
        this.tagTitle = '添加标签';
        this.addTagFormVisible = true;
        this.addTagForm = {}
      },
      //编辑
      handleEdit(row) {
        if (row.status != 2) {
          this.addTagFormVisible = true;
          this.addTagForm = Object.assign({}, row);
        } else {
          this.$message.error('该条投诉已处理')
        }
      },
      closeDialog() {
        this.addTagFormVisible = false;
        this.$refs['addTagForm'].clearValidate();
      },
      addTagFormSave(form) {
        this.$refs[form].validate(valid => {
          if (valid) {
            appComplaintSave({
              ...this.addTagForm
            }).then(res => {
              this.addTagFormVisible = false;
              this.$message.success(res.msg);
              this.getComplaintList()
            }).catch(error => {

            })
          }
        })
      },
    }
  }
</script>

<style lang="scss">
  .el-textarea textarea {
    height: 100px;
  }
</style>
<style scoped lang="scss">
  @import "~element-ui/packages/theme-chalk/src/common/var";

  .red {
    color: $--color-danger;
  }

  .green {
    color: $--color-primary;
  }

  .warning {
    color: $--color-warning;
  }
</style>
